package com.foreveross.taskservice.core.domain.task.assign.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.foreveross.taskservice.core.domain.task.TaskQueueRecordEntity;
import com.foreveross.taskservice.core.domain.task.TaskTemplateAssignDayEntity;
import com.foreveross.taskservice.core.domain.task.TaskTemplateEntity;
import com.foreveross.taskservice.core.domain.task.assign.AssignBuildQueue;
import com.foreveross.taskservice.infra.util.DateUtil;
/**
 * 未来多少天内，指定去程日期，指定返程日期的任务模板
 * @author xiangsf 2014-08-22
 *
 */
@Component("dayAssignBuildQueue")
public class DayBuildQueueBean implements AssignBuildQueue {

	@Override
	public List<TaskQueueRecordEntity> build(TaskTemplateAssignDayEntity ta) {
		List<TaskQueueRecordEntity> list = new ArrayList<TaskQueueRecordEntity>();
		TaskTemplateEntity template = ta.getTemplate();
		if(ta.getFutureCycle()!=null && ta.getFutureCycle()>0){
			//ta.getAssignFlightDay() 这个值代表从第几天开始,
			//比如getAssignFlightDay=0,getFutureCycle=90, 则代表未来0-90天
			for(int i = ta.getAssignFlightDay() ;i < ta.getFutureCycle(); i++){
				list.add(new TaskQueueRecordEntity(
						template.getFromCity(), template.getFromCityName(), template.getToCity(), template.getToCityName(),
						DateUtil.getDateAfter(i),
						DateUtil.getDateAfter(i+ta.getAssignRoundDay()),
						template.getIsInternational()==null?0:template.getIsInternational().intValue(), template.getIsReturn()==null?0:template.getIsReturn(), 
										template.getGrabChannelId(), template.getGrabChannel(), template.getAreaCode(), template.getAreaName(), template.getAttachHbaseKey(), template.getPriority()));
			}
		}
		return list;
	}

}
